package com.yuan.model_app.rest;

import com.yuan.model_common.dto.CommonQueryCriteria;
import com.yuan.model_community.service.CommunityBuildingService;
import com.yuan.model_community.service.CommunityHouseService;
import com.yuan.model_community.service.CommunityUnitService;
import com.yuan.model_community.service.dto.CommunityBuildingDto;
import com.yuan.model_community.service.dto.CommunityHouseDto;
import com.yuan.model_community.service.dto.CommunityUnitDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "物业便民: 其他临时接口")
@RestController
@RequestMapping("/api/other/temp")
@RequiredArgsConstructor
public class OtherTempController {

    private final CommunityBuildingService communityBuildingService;

    private final CommunityUnitService communityUnitService;

    private final CommunityHouseService communityHouseService;

    @GetMapping("/findAllBuildingList")
    @Log("查询/api/other/temp/building/list")
    @ApiOperation("查询/other/temp/building/list")
    public List<CommunityBuildingDto> findAllBuildingList(){
         return  communityBuildingService.queryAll();
    }

    @GetMapping("/findUnitListByBuildingId")
    @Log("查询/api/other/temp/unit/list")
    @ApiOperation("查询/other/temp/unit/list")
    public List<CommunityUnitDto> findUnitListByBuildingId(Integer buildingId){
        CommonQueryCriteria cq = new CommonQueryCriteria();
        cq.setBuildingId(buildingId);
        return communityUnitService.queryAll(cq);
    }

    @GetMapping("/findHouseListByBuildingId")
    @Log("查询/api/other/temp/house/list")
    @ApiOperation("查询/other/temp/house/list")
    public List<CommunityHouseDto> findHouseListByBuildingId(Integer buildingId){
        CommonQueryCriteria cq = new CommonQueryCriteria();
        cq.setBuildingId(buildingId);
        return communityHouseService.queryAll(cq);
    }

    @GetMapping("/findHouseListByUnitId")
    @Log("查询/api/other/temp/houseU/list")
    @ApiOperation("查询/other/temp/houseU/list")
    public List<CommunityHouseDto> findHouseListByUnitId(Integer unitId){
        CommonQueryCriteria cq = new CommonQueryCriteria();
        cq.setBuildingId(unitId);
        return communityHouseService.queryAll(cq);
    }

    @GetMapping("/findUserListByUnitId")
    @Log("查询/api/other/temp/user/list")
    @ApiOperation("查询/other/temp/user/list")
    public Map<Long, String> findUserListByUnitId(Integer unitId){
        CommonQueryCriteria cq = new CommonQueryCriteria();
        cq.setBuildingId(unitId);
        List<CommunityHouseDto> communityHouseDtos = communityHouseService.queryAll(cq);
        Map<Long,String> userMaps = new HashMap<Long,String>();

        for (CommunityHouseDto communityHouseDto : communityHouseDtos) {
            if (communityHouseDto.getLiverId() != null){
                userMaps.put(communityHouseDto.getLiverId(),communityHouseDto.getLiverName());
            }
        }
        return userMaps;
    }


}
